home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / lib / rle_w.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  3.1 KB  |  105 lines

  1. /*
  2. %    RLE_Write . C
  3. %
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5.  
  6. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  7. Permission is granted to reproduce this software for non-commercial
  8. purposes provided that this notice is left intact.
  9.  
  10. It is acknowledged that the U.S. Government has rights to this software
  11. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  12. and the University of California.
  13.  
  14. This software is provided as a professional and academic contribution
  15. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  16. with no warranties of any kind whatsoever, no support, no promise of
  17. updates, or printed documentation. By using this software, you
  18. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  19. University of California shall have no liability with respect to the
  20. infringement of other copyrights by any part of this software.
  21.  
  22. For further information about this notice, contact William Johnston,
  23. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  24. (wejohnston@lbl.gov)
  25.  
  26. For further information about this software, contact:
  27.         Jin Guojun
  28.         Bld. 50B, Rm. 2275, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  29.         g_jin@lbl.gov
  30.  
  31. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  32. %
  33. % AUTHOR:    Jin Guojun - LBL    12/1/91
  34. */
  35.  
  36. #ifndef    RLE_IMAGE
  37. #define    RLE_IMAGE
  38. #endif
  39.  
  40. #if    !defined LKT && !defined FLOAT_LKT_REQUIRED
  41. #define    LKT    int    /*    for window application    */
  42. #endif
  43.  
  44. #include "header.def"
  45. #include "imagedef.h"
  46.  
  47. write_rle(img, lkt, mapped /* from src to dest */)
  48. U_IMAGE    *img;
  49. LKT    *lkt;
  50. {
  51. register int    i, j, ch;
  52. byte    *pp[3], *dp[3];
  53. int    w, h, X0=0;
  54.  
  55.     if (img->sub_img)
  56.         w = img->sub_img_w,
  57.         h = img->sub_img_h,
  58.         X0 = img->sub_img_x;
  59.     else    w =img->width,    h = img->height;
  60.  
  61.     rle_dflt_hdr.rle_file = img->OUT_FP;
  62.     if (lkt) {
  63.         dp[0] = (byte*) zalloc(w*3, sizeof(*dp[0]), "dp");
  64.         dp[1] = dp[0] + w;
  65.         dp[2] = dp[1] + w;
  66.     }
  67.     rle_dflt_hdr.xmin = rle_dflt_hdr.ymin = 0;
  68.     rle_dflt_hdr.xmax = w - 1;
  69.     rle_dflt_hdr.ymax = h - 1;
  70.     rle_dflt_hdr.ncolors = img->dpy_channels;
  71.     if (img->color_form==CFM_SCF) /* if not mapped, cmap is in reg */
  72.         regmap_to_rlemap(img->cmap ? img->cmap : reg_cmap,
  73.             img->cmaplen, 3, &rle_dflt_hdr);
  74.     else    rle_dflt_hdr.ncmap = rle_dflt_hdr.cmaplen =
  75.         (int)(rle_dflt_hdr.cmap = NULL);    /* must be 0 !    */
  76.     rle_put_setup(&rle_dflt_hdr);
  77.  
  78.     for (i=0; i<h; i++) {
  79.         if (mapped)
  80.         pp[0] = SAVED_RLE_ROW(img, (img->sub_img ?
  81.         img->sub_img_y+img->sub_img_h :    img->height) - i) + X0;
  82.         else
  83.         pp[0] = ORIG_RLE_ROW(img, (img->sub_img ?
  84.         img->sub_img_y+img->sub_img_h :    img->height) - i) + X0;
  85.         pp[1] = pp[0] + img->width;
  86.         pp[2] = pp[1] + img->width;
  87.         if (lkt) {
  88.         for (ch=0; ch<img->channels; ch++)    {
  89.         register LKT    *lktp = lkt + ch*MaxColors;
  90.             if (img->update && img->sub_img)
  91.                 memcpy(dp[ch], pp[ch], w);
  92.             else
  93.                 for (j=0; j<w; j++)
  94.                 dp[ch][j] = lktp[pp[ch][j]];
  95.         }
  96.         rle_putrow(dp, w, &rle_dflt_hdr);
  97.         }
  98.         else    rle_putrow(pp, w, &rle_dflt_hdr);
  99.     }
  100.     rle_puteof(&rle_dflt_hdr);    /* for multi-frame images only    */
  101.  
  102.     if (lkt)    free(dp[0]);
  103.     img->update = False;
  104. }
  105.